package model

import (
	"database/sql"
	"time"
)

type SaleOrder struct {
	ResCommon
	PartnerId         int64        `json:"partner_id"`          //客户
	PartnerInvoiceId  int64        `json:"partner_invoice_id"`  //结算地址
	PartnerShippingId int64        `json:"partner_shipping_id"` //送货地址
	Partner           ResPartner   //客户
	PartnerInvoice    ResPartner   `gorm:"foreignKey:PartnerInvoiceId"`  //结算地址
	PartnerShipping   ResPartner   `gorm:"foreignKey:PartnerShippingId"` //送货地址
	DateOrder         time.Time    `json:"date_order"`                   //订单日期
	ValidityDate      sql.NullTime `json:"validity_date"`                //有效期日期
	Name              string       `json:"name"`                         //号码
	AmountUntaxed     float64      `json:"amount_untaxed"`               //未含税金额
	AmountTax         float64      `json:"amount_tax"`
	AmountTotal       float64      `json:"amount_total"`
	CurrencyRate      float64      `json:"currency_rate"`
	State             string       `json:"state"` //状态
	//IsEmergency       bool         `json:"is_emergency"` //紧急
	//ContactsId     int64        `json:"contacts_id"` //联系人
	//ResPartner     ResPartner   `gorm:"foreignKey:ContactsId"`
	//PaymentAmount  float64      `json:"payment_amount"`  //金额
	//PaymentCode    string       `json:"payment_code"`    //支付编号
	CommitmentDate sql.NullTime `json:"commitment_date"` //交货日期
	UserId         int64
	User           ResUsers
	CompanyId      int64
	Company        ResCompany
	PricelistId    int64
}

type SaleOrderLine struct {
	ResCommon
	Name          string  `json:"name"` //商品
	InvoiceStatus string  `json:"invoice_status"`
	QtyDelivered  float64 `json:"qty_delivered"`  //已交付
	QtyInvoiced   float64 `json:"qty_invoiced"`   //已开票
	PriceUnit     float64 `json:"price_unit"`     //单价
	PriceReduce   float64 `json:"price_reduce"`   //减免
	Discount      float64 `json:"discount"`       //折扣
	PriceSubtotal float64 `json:"price_subtotal"` //价格小计
	ProductId     int64   `json:"product_id"`     //产品
	Product       ProductProduct
	PriceTax      float64 `json:"price_tax"`   //
	PriceTotal    float64 `json:"price_total"` //价格
	State         string  `json:"state"`       //状态
	ProductUom    int64   `json:"product_uom"` //单位
	Uom           UomUom  `gorm:"foreignKey:ProductUom"`
	ProductUomQty float64 `json:"product_uom_qty"` //数量
	//DateOrder     time.Time `json:"date_order"`      //单据日期
	//OrderName     string    `json:"order_name"`      //单据编号
	Order        SaleOrder
	OrderId      int64
	CompanyId    int64
	CustomerLead float64
}

type UomUom struct {
	ResCommon
	CategoryId int64
	UomType    string
	Name       string
	Rounding   float32
	Active     bool
}
